Skip to content

Simplify SortedDocIDMerger.next()#16073

Merged
ChrisHegarty merged 5 commits into
apache:mainfrom
Tim-Brooks:doc_id_merge_clean-ups
May 22, 2026
Merged

Simplify SortedDocIDMerger.next()#16073
ChrisHegarty merged 5 commits into
apache:mainfrom
Tim-Brooks:doc_id_merge_clean-ups

Conversation

@Tim-Brooks
Copy link
Copy Markdown
Contributor

The else if (queue.size() > 0) guard is always true when reached:
an empty queue sets queueMinDocID to NO_MORE_DOCS, so any valid nextDoc
satisfies nextDoc < queueMinDocID and takes the fast path first. Replace
with else and add a comment explaining why the queue is never empty
at that point.

- Drop the `else if (queue.size() > 0)` guard in next(): the queue is
guaranteed non-empty when that branch is reached, since an empty queue
sets queueMinDocID to NO_MORE_DOCS and any valid nextDoc would have
taken the fast path. Add a comment explaining the invariant.

- Simplify reset() by handling the first sub before the loop, removing
the `boolean first` flag and the dead `current = null` assignment.
@github-actions github-actions Bot added this to the 10.5.0 milestone May 15, 2026
Copy link
Copy Markdown
Contributor

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ChrisHegarty ChrisHegarty merged commit f96e269 into apache:main May 22, 2026
13 checks passed
ChrisHegarty pushed a commit that referenced this pull request May 22, 2026
The else if (queue.size() > 0) guard is always true when reached:
an empty queue sets queueMinDocID to NO_MORE_DOCS, so any valid nextDoc
satisfies nextDoc < queueMinDocID and takes the fast path first. Replace
with else and add a comment explaining why the queue is never empty
at that point.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants